import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: '网页的页签栏标题',
    home: Scaffold(
      // 顶部操作栏
      appBar: AppBar(
        title: Text('标题'),
        backgroundColor: Colors.pink,
      ),
      // 配出正文主题部分
      body: Main(),
    ),
  ));
}

class Main extends StatefulWidget {
  const Main({Key? key}) : super(key: key);

  @override
  _MainState createState() => _MainState();
}

class _MainState extends State<Main> {
  Dio dio = Dio();

  @override
  void initState() {
    loadData();
    super.initState();
  }

  void loadData() async {
    // 1. 下包dio
    // 2. 封装请求方法
    // 3. 在initState中调用方法
    // 4. Response是请求返回的数据类型
    Response res = await dio.get('https://mock.boxuegu.com/mock/1172/orders');

    print(res);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.all(5),
        // 1. 使用build构造函数
        child: GridView.builder(
          gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
              maxCrossAxisExtent: 100,
              mainAxisSpacing: 10,
              crossAxisSpacing: 10),
          itemBuilder: (BuildContext context, int index) {
            return Container(
              child: Text('A$index'),
              color: Colors.amber,
            );
          },
        ));
  }
}
